package com.foreknow.dao.impl;

import com.foreknow.bean.Admin;
import com.foreknow.dao.AdminDao;
import com.foreknow.db.DBManager;
import com.foreknow.db.JdbcTemplate;
import com.foreknow.mapping.AdminMapping;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;

import java.sql.Connection;
import java.util.List;

public class AdminDaoImpl extends BaseDAO implements AdminDao {
    @Override
    public Admin login(String username, String password) {
        //要从工厂类Map容器中获取到AdminMapping对象
        EntityMapping mapping = mappingFactory.getMap(MappingFactory.ADMIN_MAPPING);
        //调用query方法
        List<Object> list = jdbcTemplate.query("select * from admin where username=? and password=?",mapping,username,password);
        if(list.size()>0){
           Admin admin = (Admin)list.get(0);
           return admin;
        }else {
            return null;
        }
    }
}
